#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinary Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


Program 1.4.2 - Coupon collector simulation

Syntax:
python couponcollector.py 1000


Notes:
int(sys.argv[1]) == Integer.parseInt(args[0])

sys is a required import here in order to use command line arguments.
https://docs.python.org/2/tutorial/stdlib.html

random is a required import as a substitute for Java's Math.random()
https://docs.python.org/2/library/random.html

'''


import sys
import random


def main():
    ''' Generate random numbers from 0 to N-1 until every possible value '''

    try:
        sim_range = int(sys.argv[1])
    except IndexError:
        print 'Integer for simulation range is required!'
        print 'Syntax: "python couponcollector.py 1000"'
        sys.exit(0)

    found = range(sim_range)
    for item in found:
        found[item] = False

    # Alternate using list comprehension:
    # found = [False for _ in range(sim_range)]

    card_count = 0
    value_count = 0

    while value_count < sim_range:
        value = int(random.random() * sim_range)
        card_count += 1

        if not found[value]:
            value_count += 1
            found[value] = True

    print card_count


if __name__ == '__main__':
    main()
